package Util::Comments::CommentsForTuan;
use Moose;
use namespace::autoclean;

has 'schema' => (
	is => 'rw',
	required => 1,
	isa => 'DBIx::Class::Schema',
);

sub get_comm_count {
	my ($self, $comm_id) = @_;

	return $self->schema->resultset('Comment')->search(
                {'me.comm_item_id' => $comm_id
                },
                {}
        )->count;
}

sub search {
	my ($self, $comm_id, $page) = @_;

	my @comments = $self->schema->resultset('Comment')->search(
		{'me.comm_item_id' => $comm_id},
		{
			select => [
				'created',
				'user_id',
				'users.photo',
				'users.username',
				'content'
			],
			as => [qw/
				created
				user_id
				photo
				user_name
				content
			/],
			order_by=>{-desc=>"me.created"},
			page => $page,
			join=>'users'
		}
	);

	return \@comments;
}

__PACKAGE__->meta->make_immutable;

1;
